package main

import (
	"fmt"
	"strconv"
	"strings"
	"time"
)

func main() {

	// 字符串和日期练习
	//strAndDate()

	//对内置函数的练习
	internalFunc()

}

func strAndDate() {
	//	内置函数不需要导包，可以直接使用
	str := "let's go golang"
	fmt.Println(len(str))

	//	字符串转int
	v, _ := strconv.Atoi("9899")
	fmt.Println(v + 1)

	//int转字符串
	str = strconv.Itoa(1984)
	fmt.Println(str + "1")

	//	统计一个字符串有几个指定的子串
	count := strings.Count("golangohgolangmygade", "go")
	fmt.Println(count)

	//	忽略大小写字符串比较
	flag := strings.EqualFold("GOLANG", "golang")
	fmt.Println(flag)

	//	不忽略大小写字符串比较
	fmt.Println("GOLANG" == "golang")

	//	返回子串再字符串中第一次出现的索引值，没有返回-1
	fmt.Println(strings.Index("golangohgolangmygade", "go"))

	//	strings.替换;
	//strings.Replace("golandjavaphp", "land")

	//	日期和时间函数
	now := time.Now()
	fmt.Println(now)
	fmt.Printf("now=%v----类型%T", now, now)

	fmt.Printf("年:%v \n", now.Year())
	fmt.Printf("月:%v \n", now.Month())
	fmt.Printf("月:%v \n", int(now.Month()))
	fmt.Printf("日:%v \n", now.Day())
	fmt.Printf("时:%v \n", now.Hour())
	fmt.Printf("分:%v \n", now.Minute())
	fmt.Printf("秒:%v \n", now.Second())
	fmt.Println("----------------------------------")
	fmt.Printf("%d-%d-%d %d:%d:%d  \n", now.Year(), now.Month(), now.Day(), now.Hour(), now.Minute(), now.Second())

	tranStr := fmt.Sprintf("%d-%d-%d %d:%d:%d  \n", now.Year(), now.Month(), now.Day(), now.Hour(), now.Minute(), now.Second())
	fmt.Println(tranStr)
	fmt.Println("----------------------------------")

	tranStr2 := now.Format("2006/01/02 15:04:05")
	fmt.Println(tranStr2)
}

func internalFunc() {
	num := new(int)
	fmt.Printf("num的类型：%T    num的值：%v      num的地址：%v    num的指针指向的值是：%v", num, num, &num, *num)
}
